load("//tools/lint:lint.bzl", "add_lint_tests")
load("//tools/skylark:drake_py.bzl", "drake_py_unittest")

config_setting(
    name = "enabled",
    flag_values = {"//tools/flags:with_nlopt": "True"},
)

exports_files(
    ["patches/gen_enums.patch"],
    visibility = ["@nlopt_internal//:__pkg__"],
)

# Creates api/nlopt.hpp using NLopt upstream's codegen so that we can
# cross-check it versus our Drake-local patch file.
genrule(
    name = "cmake_genrule",
    srcs = [
        "@nlopt_internal//:cmake/generate-cpp.cmake",
        "@nlopt_internal//:src/api/nlopt-in.hpp",
        "@nlopt_internal//:src/api/nlopt.h",
    ],
    outs = ["test/nlopt-upstream.hpp"],
    cmd = " ".join([
        "cmake",
        "-DAPI_SOURCE_DIR=$$(dirname $(execpath @nlopt_internal//:src/api/nlopt.h))",  # noqa
        "-P $(execpath @nlopt_internal//:cmake/generate-cpp.cmake)",
        "&&",
        "mv nlopt.hpp $@",
    ]),
    tags = [
        "manual",
        "nolint",
    ],
)

drake_py_unittest(
    name = "enum_test",
    data = [
        ":test/nlopt-upstream.hpp",
        "@nlopt_internal//:genrule/nlopt.hpp",
    ],
    deps = [
        "@rules_python//python/runfiles",
    ],
)

add_lint_tests()
